<!-- 活动新增 -->
<template>
	<div class="dynamic-form-container layout-pd">
		<el-card shadow="hover" header="新增活动">
			<template #header>
				<div class="card-header">
					<span>新增活动</span>
					<el-button type="primary" size="mini" @click="$router.back()">返回</el-button>
				</div>
			</template>
			<div class="personal-edit-title">
				<span>基本信息</span>
				
			</div>
			<el-form :model="state.form" ref="formRulesOneRef" :rules="state.rules"  label-width="140px" class="mt35">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-row>
							<el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="8">
								<el-form-item label="活动名称">
									<el-input v-model="state.form.name" placeholder="请输入活动名称" style="width: 100%" clearable></el-input>
								</el-form-item>
							</el-col>
						</el-row>	
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-row>
							<el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="8">
								<el-form-item label="活动时间">
									<el-date-picker v-model="state.form.dateTime" type="daterange" unlink-panels
										format="YYYY/MM/DD" value-format="YYYY-MM-DD" range-separator="-"
										start-placeholder="开始日期" end-placeholder="结束日期" />
								</el-form-item>
							</el-col>
						</el-row>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-row>
							<el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="8">
								<el-form-item label="活动售价">
									<el-input v-model="state.form.money" placeholder="请输入活动售价">
										<template #append>元</template>
									</el-input>
								</el-form-item>
							</el-col>
						</el-row>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-row>
							<el-col :xs="12" :sm="12" :md="12" :lg="12" :xl="8">
								<el-form-item label="最低售价">
									<el-input v-model="state.form.minMoney" placeholder="请输入最低售价">
										<template #append>元</template>
									</el-input>
								</el-form-item>
							</el-col>
						</el-row>
					</el-col>	
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="是否关联商品">
							<el-radio-group  v-model="state.form.isGood"> 
								<el-radio :label="true">关联</el-radio>
								<el-radio :label="false">不关联</el-radio>
							</el-radio-group>
							<span style="width: 50px;"></span>
							<el-button v-if="state.form.isGood"  type="primary" @click="addCommodity()">
								<SvgIcon name="iconfont icon-shuxing" />
								选择商品
							</el-button>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16" class="mb20" v-if="state.form.isGood && state.selectGoodsTableData.length > 0">
						<el-form-item label=" ">
							<el-table :data="state.selectGoodsTableData" border style="width: 100%;">
								<el-table-column prop="id" label="ID" width="80" />
								<el-table-column label="图片" show-overflow-tooltip width="80">
									<template #default="scope">
										<el-image style="width:32px; height: 32px;"
											src="https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500"
											fit="cover" />
									</template>
								</el-table-column>
								<el-table-column prop="title" label="商品名称" show-overflow-tooltip>
									<template #default="scope">
										<span>{{ scope.row.name }}</span>
									</template>
								</el-table-column>
                    			<el-table-column prop="id" label="零售价" show-overflow-tooltip></el-table-column>
								<el-table-column prop="id" label="数量" show-overflow-tooltip>
									<template #default="scope">
										<el-input-number :min="1" />
									</template>
								</el-table-column>
								<el-table-column prop="title" label="操作" show-overflow-tooltip>
									<template #default="scope">
										<span>删除</span>
									</template>
								</el-table-column>
                			</el-table>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="是否关联储值卡">
							<el-radio-group  v-model="state.form.isPrepaidCard"> 
								<el-radio :label="true">关联</el-radio>
								<el-radio :label="false">不关联</el-radio>
							</el-radio-group>
							<span style="width: 50px;"></span>
							<el-button v-if="state.form.isPrepaidCard"  type="primary" @click="addCommodity()">
								<SvgIcon name="iconfont icon-shuxing" />
								选择储值卡
							</el-button>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16" class="mb20" v-if="state.form.isPrepaidCard && state.selectGoodsTableData.length > 0">
						<el-form-item label=" ">
							<el-table :data="state.selectGoodsTableData" border style="width: 100%;">
								<el-table-column prop="id" label="ID" width="80" />
								<el-table-column label="图片" show-overflow-tooltip width="80">
									<template #default="scope">
										<el-image style="width:32px; height: 32px;"
											src="https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500"
											fit="cover" />
									</template>
								</el-table-column>
								<el-table-column prop="title" label="商品名称" show-overflow-tooltip>
									<template #default="scope">
										<span>{{ scope.row.name }}</span>
									</template>
								</el-table-column>
                    			<el-table-column prop="id" label="零售价" show-overflow-tooltip></el-table-column>
								<el-table-column prop="id" label="数量" show-overflow-tooltip>
									<template #default="scope">
										<el-input-number :min="1" />
									</template>
								</el-table-column>
								<el-table-column prop="title" label="操作" show-overflow-tooltip>
									<template #default="scope">
										<span>删除</span>
									</template>
								</el-table-column>
                			</el-table>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="是否关联卡项">
							<el-radio-group  v-model="state.form.isServeCard"> 
								<el-radio :label="true">关联</el-radio>
								<el-radio :label="false">不关联</el-radio>
							</el-radio-group>
							<span style="width: 50px;"></span>
							<el-button v-if="state.form.isServeCard"  type="primary" @click="addCommodity()">
								<SvgIcon name="iconfont icon-shuxing" />
								选择服务卡项
							</el-button>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16" class="mb20">
						<el-form-item label=" ">
							<el-table :data="state.selectGoodsTableData" border style="width: 100%;">
								<el-table-column prop="id" label="卡项名" width="80" /> 
								<el-table-column prop="title" label="卡项售价" show-overflow-tooltip>
									<template #default="scope">
										<span>{{ scope.row.name }}</span>
									</template>
								</el-table-column>
                    			<el-table-column prop="id" label="赠送数量" show-overflow-tooltip></el-table-column>
								<el-table-column prop="id" label="数量" show-overflow-tooltip>
									<template #default="scope">
										<el-input-number :min="1" />
									</template>
								</el-table-column>
								<el-table-column prop="title" label="操作" show-overflow-tooltip>
									<template #default="scope">
										<el-link type="danger">删除</el-link>
									</template>
								</el-table-column>
                			</el-table>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="是否关联代金券">
							<el-radio-group  v-model="state.form.isCouponSelect"> 
								<el-radio :label="true">关联</el-radio>
								<el-radio :label="false">不关联</el-radio>
							</el-radio-group>
							<span style="width: 50px;"></span>
							<el-button v-if="state.form.isCouponSelect"  type="primary" @click="addCommodity()">
								<SvgIcon name="iconfont icon-shuxing" />
								选择代金券
							</el-button>
						</el-form-item>
					</el-col>
					<el-col :xs="24" :sm="24" :md="24" :lg="16" :xl="16" class="mb20" v-if="state.form.isCouponSelect && state.selectGoodsTableData.length > 0">
						<el-form-item label=" ">
							<el-table :data="state.selectGoodsTableData" border style="width: 100%;">
								<el-table-column prop="id" label="ID" width="80" />
								<el-table-column label="图片" show-overflow-tooltip width="80">
									<template #default="scope">
										<el-image style="width:32px; height: 32px;"
											src="https://img2.baidu.com/it/u=1978192862,2048448374&fm=253&fmt=auto&app=138&f=JPEG?w=504&h=500"
											fit="cover" />
									</template>
								</el-table-column>
								<el-table-column prop="title" label="商品名称" show-overflow-tooltip>
									<template #default="scope">
										<span>{{ scope.row.name }}</span>
									</template>
								</el-table-column>
                    			<el-table-column prop="id" label="零售价" show-overflow-tooltip></el-table-column>
								<el-table-column prop="id" label="数量" show-overflow-tooltip>
									<template #default="scope">
										<el-input-number :min="1" />
									</template>
								</el-table-column>
								<el-table-column prop="title" label="操作" show-overflow-tooltip>
									<template #default="scope">
										<span>删除</span>
									</template>
								</el-table-column>
                			</el-table>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
			<div class="personal-edit-title">其它信息</div>
			<el-form :model="state.form" ref="formRulesOneRef" :rules="state.rules"  label-width="140px" class="mt35">
				<el-row :gutter="35">
					<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
						<el-form-item label="是否参与岗位业绩">
							<el-radio-group  v-model="state.form.isGood"> 
								<el-radio :label="true">是</el-radio>
								<el-radio :label="false">否</el-radio>
							</el-radio-group>
							<span style="width: 50px;"></span>
							<el-form v-if="state.form.isGood">
								<el-form-item label="销售业绩">
									<el-input-number :min="1" />
								</el-form-item>
							</el-form>
						</el-form-item> 
						<el-form-item label="是否限购">
							<el-radio-group  v-model="state.form.isGood"> 
								<el-radio :label="true">是</el-radio>
								<el-radio :label="false">否</el-radio>
							</el-radio-group> 
						</el-form-item>
						<el-form-item label="允许门店修改">
							<el-radio-group  v-model="state.form.isGood"> 
								<el-radio :label="true">是</el-radio>
								<el-radio :label="false">否</el-radio>
							</el-radio-group> 
						</el-form-item>
						<el-form-item label="是否允许欠款">
							<el-radio-group  v-model="state.form.isGood"> 
								<el-radio :label="true">是</el-radio>
								<el-radio :label="false">否</el-radio>
							</el-radio-group> 
						</el-form-item>
						<el-form-item label="选择销售门店">
							<el-tag closable class="store-item">门店1</el-tag><el-tag closable class="store-item">门店2</el-tag>
							<el-button type="primary" size="mini">选择销售门店</el-button>
						</el-form-item>
					</el-col>
				</el-row>
				<section style="text-align: center;">
					<el-button type="primary" size="large">提 交</el-button>
				</section>
			</el-form>
		</el-card>
		<goodSelectDialog ref="goodSelectDialogRef"></goodSelectDialog>
	</div>
</template>

<script setup lang="ts" name="pagesDynamicForm">
import { reactive, ref, defineAsyncComponent } from 'vue';
import { ElMessage } from 'element-plus';
import type { FormInstance } from 'element-plus';
import { number } from 'echarts';
// 引入组件
const goodSelectDialog = defineAsyncComponent(() => import('/@/components/dialog/goodSelect.vue'));
// 定义变量内容

const goodSelectDialogRef = ref();

const formRulesOneRef = ref<FormInstance>();
const state = reactive({
	form: {
		name: '',
		dateTime: '',
		money: 0,
		minMoney: 0,
		isGood: false,
		isPrepaidCard: false,
		isServeCard: false,
		isCouponSelect: false,
	},
	selectGoodsTableData:[{},{}],
	rules: {
		name: { required: true, message: '请输入活动名称', trigger: 'blur' },
		email: { required: true, message: '请输入用户邮箱', trigger: 'blur' },
		autograph: { required: true, message: '请输入登陆账户名', trigger: 'blur' },
		occupation: { required: true, message: '请选择职务', trigger: 'change' },
	},
	goodsTableData:[

	]
});

const addCommodity = () => {
	goodSelectDialogRef.value.openDialog();
}


// 表单验证
const onSubmitForm = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.validate((valid: boolean) => {
		if (valid) {
			ElMessage.success('验证成功');
		} else {
			return false;
		}
	});
};
// 重置表单
const onResetForm = (formEl: FormInstance | undefined) => {
	if (!formEl) return;
	formEl.resetFields();
};
</script>
<style scoped lang="scss">

.personal-edit-title {
	position: relative;
	padding-left: 10px;
	color: var(--el-text-color-regular);
	&::after {
		content: '';
		width: 2px;
		height: 10px;
		position: absolute;
		left: 0;
		top: 50%;
		transform: translateY(-50%);
		background: var(--el-color-primary);
	}
}
.store-item{
	margin: 0 10px 0px 0;
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
</style>
